//-----------------------------------------------------------------------
//<copyright file="CongTyDAO.cs
//Code generate by tools.
//</copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using PMS.Exceptions;
using System.Data.SqlClient;
using PMS.Entity;

namespace PMS.DAL
{
	public class CongTyDAO : SQLDatabase, ICongTyDAO
	{

		#region Create CongTy methods

		public CongTy CreateCongTy(CongTy congTy)
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spCongTyInsert");
				AddOutParameter(command, "@MaCTy", SqlDbType.Int, congTy.MaCTy);
				AddInParameter(command, "@TenCTy", SqlDbType.NVarChar, congTy.TenCTy);
				AddInParameter(command, "@DiaChi", SqlDbType.NVarChar, congTy.DiaChi);
				AddInParameter(command, "@SoDT", SqlDbType.NVarChar, congTy.SoDT);
				AddInParameter(command, "@SoFax", SqlDbType.NVarChar, congTy.SoFax);
				AddInParameter(command, "@MaSoThue", SqlDbType.NVarChar, congTy.MaSoThue);
				AddInParameter(command, "@Email", SqlDbType.NVarChar, congTy.Email);
				AddInParameter(command, "@Website", SqlDbType.NVarChar, congTy.Website);
				AddInParameter(command, "@NguoiLienHe", SqlDbType.NVarChar, congTy.NguoiLienHe);
				AddInParameter(command, "@Logo", SqlDbType.NVarChar, congTy.Logo);
				AddInParameter(command, "@GhiChu", SqlDbType.NVarChar, congTy.GhiChu);

				ExecuteNonQuery(command);
				congTy.MaCTy = (int)GetParameterValue(command, "@maCTy");
				return congTy;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access CreateCongTyException", ex);
			}
		}

		#endregion

		#region Update CongTy methods

		public void UpdateCongTy(CongTy congTy)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spCongTyUpdate");

				AddInParameter(command, "@MaCTy", SqlDbType.Int, congTy.MaCTy);
				AddInParameter(command, "@TenCTy", SqlDbType.NVarChar, congTy.TenCTy);
				AddInParameter(command, "@DiaChi", SqlDbType.NVarChar, congTy.DiaChi);
				AddInParameter(command, "@SoDT", SqlDbType.NVarChar, congTy.SoDT);
				AddInParameter(command, "@SoFax", SqlDbType.NVarChar, congTy.SoFax);
				AddInParameter(command, "@MaSoThue", SqlDbType.NVarChar, congTy.MaSoThue);
				AddInParameter(command, "@Email", SqlDbType.NVarChar, congTy.Email);
				AddInParameter(command, "@Website", SqlDbType.NVarChar, congTy.Website);
				AddInParameter(command, "@NguoiLienHe", SqlDbType.NVarChar, congTy.NguoiLienHe);
				AddInParameter(command, "@Logo", SqlDbType.NVarChar, congTy.Logo);
				AddInParameter(command, "@GhiChu", SqlDbType.NVarChar, congTy.GhiChu);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access UpdateCongTyException", ex);
			}
		}

		#endregion

		#region Delete CongTy methods

		public void DeleteCongTy(CongTy congTy)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spCongTyDelete");

				AddInParameter(command, "@MaCTy", SqlDbType.Int, congTy.MaCTy);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access DeleteCongTyException", ex);
			}
		}

		#endregion

		#region Select methods

		#region GetAll CongTy methods

		public CongTies GetAllCongTy()
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spCongTyGetList");
				CongTies Result = new CongTies();
				List<CongTy> List = ExecuteQuery<CongTy>(command,true);
				foreach(CongTy item in List)
				{
					Result.Add(item);
				}
				return Result;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetAllCongTyException", ex);
			}
		}

		#endregion


		#region GetCongTy methods

		public CongTy GetCongTyByID(int maCTy)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spCongTyGet");

				AddInParameter(command, "@maCTy", SqlDbType.Int, maCTy);

				return ExecuteQuery<CongTy>(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetCongTyBy ID Exception", ex);
			}
		}

		#endregion


		#endregion
	}
}//End Class
